package com.zztl.infiniteBand.ui.view.recycleview

import android.content.Context
import android.graphics.Canvas
import android.graphics.Paint
import android.support.v7.widget.RecyclerView

import com.zztl.infiniteBand.R


/**
 * 创建者     ZCL
 * 创建时间   2018/5/16 14:19
 * 描述	      ${TODO}
 *
 *
 * 更新者     $Author$
 * 更新时间   $Date$
 * 更新描述   ${TODO}
 */
class SimpleItemDecoration(context: Context) : RecyclerView.ItemDecoration() {
    private val wight: Int
    private val height: Int
    private val item_height: Int
    private val item_padding: Int
    private val paint: Paint

    init {

        wight = context.resources.displayMetrics.widthPixels
        height = context.resources.displayMetrics.heightPixels
        paint = Paint(Paint.ANTI_ALIAS_FLAG or Paint.DITHER_FLAG)
        paint.color = context.resources.getColor(R.color.color_EEF1F3)

        item_height = 2

        item_padding = 8
    }


    override fun onDraw(c: Canvas, parent: RecyclerView, state: RecyclerView.State) {
        super.onDraw(c, parent, state)
        val count = parent.childCount

        for (i in 0 until count) {
            val view = parent.getChildAt(i)
            val top = view.bottom
            val bottom = top + item_height
            //分割线不要占满这里把left和right的值分别增加item_padding,和减去item_padding.
            c.drawRect(item_padding.toFloat(), top.toFloat(), (wight - item_padding).toFloat(), bottom.toFloat(), paint)
        }
    }

}
